package com.xzz.number;

/**
 * @author: hhz
 * @create: 2022-01-25 09:48
 * 1688. 比赛中的配对次数
 **/
public class NumberOfMatches {

    public static void main(String[] args) {
        System.out.println(numberOfMatches(1));
        System.out.println(numberOfMatches(7));
        System.out.println(numberOfMatches(14));
    }
    public static int numberOfMatches(int n) {
        if(n==1){
            return 0;
        }
       return matches(n);
    }
    public static int matches(int n){
        if(n==2){
            return 1;
        }else{
            if(n%2!=0){
                int t = (n-1)/2;
                return t+matches(t+1);
            }else {
                int t = n/2;
                return t+matches(t);
            }
        }
    }
}
